<html>
<head><meta charset="utf-8"><title>function pointer cast: safe arg type changes · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html">function pointer cast: safe arg type changes</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195673102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195673102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195673102">(Apr 29 2020 at 07:57)</a>:</h4>
<p>I was just looking at a situation where I would've liked to be able to do</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">bar</span><span class="p">(</span><span class="n">_</span>: <span class="kp">&amp;</span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nc">fn</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bar</span><span class="p">;</span><span class="w"></span>
</code></pre></div>


<p>I believe if that coercion would be legal, it would not be a breaking change if a public function in an API went from a mutable reference to an immutable one. I think there are other function pointer casts that could be legal. A function taking a raw pointer could be used as a function pointer with a reference argument. Basically whenever you could transmute the function pointer argument to the real function's argument without any change in ABI, such casts could be ok. Of course we don't want to lock ourselves into platform defined behaviour, but at least for references and raw pointers there should be no difference ever from an ABI perspective, right?</p>



<a name="195674312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195674312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195674312">(Apr 29 2020 at 08:09)</a>:</h4>
<p>Almost. Raw pointers can have mutable aliases, references cannot without UB, so there are circumstances where that isn't safe.</p>



<a name="195674361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195674361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195674361">(Apr 29 2020 at 08:09)</a>:</h4>
<p>But many type conversions would be fine. I think they'd need an "into" or "as" or something though.</p>



<a name="195675399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195675399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195675399">(Apr 29 2020 at 08:22)</a>:</h4>
<p>ah interesting. converting function pointers between each other via <code>into</code> would indeed be neat</p>



<a name="195729291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195729291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195729291">(Apr 29 2020 at 15:43)</a>:</h4>
<p>I feel like I'm missing something; can <span class="user-mention" data-user-id="239881">@Josh Triplett</span> or <span class="user-mention" data-user-id="124288">@oli</span> spell out the scenario that Josh is describing? (Where are you anticipating the alias of a raw pointer arising? Is it from an invocation of the function pointer <code>x</code> on a <code>*const i32</code> input?)</p>



<a name="195729826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195729826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195729826">(Apr 29 2020 at 15:45)</a>:</h4>
<p>Or wait, maybe <span class="user-mention" data-user-id="239881">@Josh Triplett</span> was talking about the generalizations that <span class="user-mention" data-user-id="124288">@oli</span> listed, such as "a function taking a raw pointer could be used as a function pointer with a reference argument ..."</p>



<a name="195729946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195729946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195729946">(Apr 29 2020 at 15:46)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span>  in any case, even looking at your original example... I'm not so sure you can make even the original coercion that you described. At least, not based on the type signatures alone</p>



<a name="195730084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730084">(Apr 29 2020 at 15:47)</a>:</h4>
<p>hmm.. why not? Is there an ABI problem?</p>



<a name="195730094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730094">(Apr 29 2020 at 15:47)</a>:</h4>
<p>Consider e.g. <code>fn baz&lt;'a&gt;(p: &amp;'a i32, q: &amp;mut &amp;'a i32) { *q = p; }</code></p>



<a name="195730160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730160">(Apr 29 2020 at 15:47)</a>:</h4>
<p>You cannot just turn the <code>&amp;'a i32</code> into a <code>&amp;'a mut i32</code> blindly</p>



<a name="195730327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730327">(Apr 29 2020 at 15:48)</a>:</h4>
<p>the soundness of the body of <code>baz</code>relies on it being sharable</p>



<a name="195730354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730354">(Apr 29 2020 at 15:48)</a>:</h4>
<p>the function still needs to compile</p>



<a name="195730392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730392">(Apr 29 2020 at 15:49)</a>:</h4>
<p>oh</p>



<a name="195730398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730398">(Apr 29 2020 at 15:49)</a>:</h4>
<p>hmm</p>



<a name="195730403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730403">(Apr 29 2020 at 15:49)</a>:</h4>
<p>maybe I misunderstand the coercion you desire</p>



<a name="195730492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730492">(Apr 29 2020 at 15:49)</a>:</h4>
<p>but if you want <code>let x: fn(&amp;mut i32) = baz;</code> to compile without knowing the body of <code>baz</code>, then you cannot blindly replace <code>&amp;T</code> with <code>&amp;mut T</code></p>



<a name="195730515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730515">(Apr 29 2020 at 15:49)</a>:</h4>
<p>basically I want to convert <code>baz</code> to a function pointer <code>for&lt;'a&gt; baz(p: &amp;'a mut i32, q: &amp;mut &amp;'a i32)</code></p>



<a name="195730601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730601">(Apr 29 2020 at 15:50)</a>:</h4>
<p>right, but you can see where that goes wrong, right?</p>



<a name="195730605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730605">(Apr 29 2020 at 15:50)</a>:</h4>
<p>but I see now that there are implications I didn't think about</p>



<a name="195730640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730640">(Apr 29 2020 at 15:50)</a>:</h4>
<p>clearly we need a richer hierarchy here. :)</p>



<a name="195730927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195730927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195730927">(Apr 29 2020 at 15:52)</a>:</h4>
<p>I would have thought a wrapper function <code>fn foo&lt;'a&gt;(p: &amp;'a mut i32, q: &amp;mut &amp;'a i32) { baz(p, q) }</code> can exist without any problems and it bascially has no code</p>



<a name="195731158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731158">(Apr 29 2020 at 15:53)</a>:</h4>
<p>hmm yes that compiles, so I'm again unsure why this specific example is a counterexample to my idea, but I see that there could be something in this space and will play a bit now to see if I can come up with problematic examples</p>



<a name="195731193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731193">(Apr 29 2020 at 15:53)</a>:</h4>
<p>let me double-check whether I am misunderstanding my own exmaple</p>



<a name="195731320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731320">(Apr 29 2020 at 15:54)</a>:</h4>
<p>Oh, right</p>



<a name="195731347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731347">(Apr 29 2020 at 15:54)</a>:</h4>
<p>its okay that it gets aliased, since its being aliased as a <code>&amp;T</code></p>



<a name="195731355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731355">(Apr 29 2020 at 15:54)</a>:</h4>
<p>not as a <code>&amp;mut T</code></p>



<a name="195731360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731360">(Apr 29 2020 at 15:54)</a>:</h4>
<p>so never mind me</p>



<a name="195731550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731550">(Apr 29 2020 at 15:56)</a>:</h4>
<p>but it would definitely be bad to convert <code>&amp;mut &amp;'a i32</code> to <code>&amp;mut &amp;'a mut i32</code></p>



<a name="195731640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195731640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195731640">(Apr 29 2020 at 15:56)</a>:</h4>
<p>right. Its probably something where you would need to apply our variance rules to determine legality</p>



<a name="195803529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195803529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195803529">(Apr 30 2020 at 06:53)</a>:</h4>
<p>Note that if you change the function ptr type, that's effectively a <em>transmute</em> of the argument from caller type to callee type</p>



<a name="195803550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195803550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195803550">(Apr 30 2020 at 06:53)</a>:</h4>
<p>transmuting a mutable ref to a shared ref is not the same as the normal coercion, in terms of Stacked Borrows</p>



<a name="195803574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195803574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195803574">(Apr 30 2020 at 06:53)</a>:</h4>
<p>but I think Stacked Borrows 2 is fine with such transmutes, and the reborrow-on-fn-entry will anyway ensure that the callee has the kind of tag/permission it expects</p>



<a name="195803630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/function%20pointer%20cast%3A%20safe%20arg%20type%20changes/near/195803630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/function.20pointer.20cast.3A.20safe.20arg.20type.20changes.html#195803630">(Apr 30 2020 at 06:54)</a>:</h4>
<p>this is something to keep in mind though in general -- we'd be introducing transmutes here, not casts. (ptr-int-casts are another example of casts that are not equivalent to transmutes.)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>